﻿using System;
using System.Data;
using Framework.Metadata;
using NUnit.Framework;
using UnitTestHelper;

namespace Framework.UnitTest.Metadata
{
    [TestFixture]
    public class ColumnPropertyMetadataFixture
    {
        //TODO: Should separate out column naming code from ColumnPropertyMetadata
        [Test]
        public void UpdateObjectFromDataRecord()
        {
            var propertyInfo = typeof (ColumnTestData) .GetProperty("StandardField");

            var columnTestData = new ColumnTestData();

            var columnPropertyMetadata = new ColumnPropertyMetadata(propertyInfo);

            var dataTable = new DataTable();
            dataTable.Columns.Add(columnPropertyMetadata.ColumnName);
            var dataRow = dataTable.Rows.Add("Test Result");
            var testRecord = TestDataRecord.FromDataRow(dataRow);

            columnPropertyMetadata.UpdateObject(columnTestData, testRecord, (type, expression, action) => { throw new Exception("Find should not be called"); });

            Assert.AreEqual("Test Result", columnTestData.StandardField);
        }

        public void UpdateSqlBuilder()
        {}
    }

    public class ColumnTestData
    {
        public string StandardField { get; set; }
    }
}